package team.lourd.network.system.socketio;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpSession;

/**
 * 简单的一对一web socket发送器
 *
 * @author JADemo
 * @date 2019/2/27 10:25
 */
@Service
public class SimpleWebSocketService {
    @Autowired
    private SimpMessagingTemplate template;

    // 发送给指定用户消息
    public void sendToSession(HttpSession session, String body) {
        String sessionId = session.getId();
        template.convertAndSendToUser(sessionId, "/msg", body);
    }
}
